package com.huilian.iotbox.admin.service.impl;

import com.huilian.iotbox.admin.dao.UserBankCardDao;
import com.huilian.iotbox.admin.service.UserBankCardService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.po.UserBankCard;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 谢洛涛
 * @date 2021/4/8 10:27
 */
@Service
public class UserBankCardServiceImpl implements UserBankCardService {
    @Resource
    private UserBankCardDao userBankCardDao;
    @Override
    public Integer checkUserBankCard(UserInfo userInfo) {
        return userBankCardDao.checkUserBankCard(userInfo);
    }

    @Override
    public ServerResponse addUserBankCard(UserBankCard userBankCard) {
        userBankCard.setCount(0);
        userBankCard.setUserId(userBankCard.getUserInfo().getId());
        Integer result = userBankCardDao.addUserBankCard(userBankCard);
        if (result == 1) {
            return ServerResponse.createBySuccess();
        } else {
            return ServerResponse.createByErrorMessage("添加失败");
        }
    }

    @Override
    public ServerResponse findUserBankCardList(UserInfo userInfo) {
        return ServerResponse.createBySuccess(userBankCardDao.findUserBankCardList(userInfo));
    }

    @Override
    public UserBankCard getBindUserBankCardByType(Integer userId, Integer type) {
        return userBankCardDao.getBindUserBankCardByType(userId,type);
    }

    @Override
    public Integer updateUserBankCardCount(UserBankCard userBankCard) {
        return userBankCardDao.updateUserBankCardCount(userBankCard);
    }
}
